{% extends 'myadmin/base.html' %}
{% block title %}
<title>Book-shop图书订单管理</title>
{% endblock %}

{% block con %}
<section class="wrapper">
    <!--overview start-->
    <div class="row">
        <div class="col-lg-8">
            <h3 class="page-header"><i class="fa fa-users"></i> 图书订单管理</h3>
        </div>
    </div>

    <section class="panel">
        <header class="panel-heading">
            图书订单列表
        </header>
        <div class="panel-body">
            <a href="{% url 'myadmin_orders_add' %}" class="btn btn-success" data-toggle="modal" href="#myModal">新增</a>
            <a class="btn btn-warning" data-toggle="modal" href="#myModal2">保存</a>

            <div class="btn-group pull-right">
                <input class="form-control" placeholder="搜索" type="text" name="keywords">
            </div>
        </div>
        <table class="table table-striped table-advance table-hover">
            <thead>
            <tr>
                <th>ID</th>
                <th>图片</th>
                <th>书名</th>
                <th>单价</th>
                <th>数量</th>
                <th>小计</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% for i in user.cart_set.all %}
            <tr>
                <th class="product-thumbnail">
                    {{i.id}}
                </th>
                <td class="thumb"><img src="/{{i.bid.bookimgs_set.first.img_url }}" alt=""
                                       style="max-width: 50px; min-width: 45px;"></td>
                <td class="details">
                    {{i.bid.title}}
                </td>
                <td>￥<strong class="amount">{{i.bid.price}}</strong><br>
                    <del class="font-weak"><small>￥30.00</small></del>
                </td>
                <td>
                    <input  name="num" type="number" min="1" value="{{i.num}}">
                    <input type="hidden" name="cartid" value="{{i.id}}">
                </td>

                <td>￥<strong class="primary-color">{% widthratio i.bid.price 1 i.num %}</strong></td>
                <td>
                    <div class="btn-group">
                        <a href="javascript:;" class="btn btn-info">编辑</a>
                        <a href="javascript:;" class="btn btn-danger">
                            <i class="icoclose_alt">删除</i></a>
                    </div>
                </td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
        <!-- <ul class="pagination"> -->
        <ul class="pagination pull-right">
            <li><a href="?page=1">首页</a></li>
            <li><a href="?page=2">上一页</a></li>
            {% for i in data.paginator.page_range %}
            <li><a href="?page={{i}}">{{i}}</a></li>
            {% endfor %}
            <li><a href="?page=3">下一页</a></li>
            <li><a href="?page={{-1}}">尾页</a></li>
        </ul>
    </section>
</section>
    <script src="/static/myadmin/assets/js/jquery-1.12.4.min.js"></script>
    <script>
      $('.icoclose_alt').click(function(){
		var res = confirm('是否确认删除商品？')
		var $this =  $(this)
		if (res){
			var cartid = $(this).parents('tr').find('input[name=cartid]').val()
			// console.log(cartid)

			$.get("{% url 'myadmin_orders_delete' %}",{'cartid':cartid},function(data){
				if (data['code']){
					alert(data['msg'])
				}else{
					$this.parents('tr').remove()
				}
			},'json')
		}

	})


    </script>
    {% endblock %}